<script>
export default {
  name: 'ChooseNext',
  props: {
    haveNextGroup: {
      type: Boolean,
      default: true
    },
    showContinue: {
      type: Boolean,
      default: false
    },
    groupIndex: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      courseTypes: []
    }
  },
  created() {
    this.courseTypes.push({ name: '重新剪纸盒', icon: '<i class="fa-solid fa-rotate-right"></i>' })
    if (this.groupIndex > 0) {
      this.courseTypes.push({ name: '自定义混组', icon: '<i class="fa-solid fa-staff-snake"></i>' })
    }
    if (this.haveNextGroup) {
      this.courseTypes.push({ name: '学习下一组', icon: '<i class="fa-solid fa-angles-right"></i>' })
    } else {
      this.courseTypes.push({ name: '全部混组', icon: '<i class="fa-solid fa-volleyball"></i>' })
      this.courseTypes.push({ name: '学后检测', icon: '<i class="fa-solid fa-list-check"></i>' })
    }
    if (this.showContinue && !this.haveNextGroup) {
      this.courseTypes.splice(this.findIndexByName('学后检测'), 1)
      this.courseTypes.push({ name: '继续学新', icon: '<i class="fa-solid fa-play"></i>' })
    }
    this.courseTypes.push({ name: '提前结课', icon: '<i class="fa-solid fa-ban"></i>' })
  },
  methods: {
    handleNextSelect(course) {
      this.$emit('handleNextSelect', course.name)
    },
    findIndexByName(name) {
      return this.courseTypes.findIndex(course => course.name === name)
    }
  }
}
</script>

<template>
  <div class="dialog-content-wrapper">
    <div class="course-type-grid">
      <div
        v-for="(course, index) in courseTypes"
        :key="index"
        class="course-type-card"
        @click="handleNextSelect(course)"
      >
        <div class="course-icon" v-html="course.icon"/>
        <div class="course-name">{{ course.name }}</div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.dialog-content-wrapper {
  display: flex;
  justify-content: center;
  padding: 15px 0;
}

.course-type-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 25px;
  width: 100%;
  max-width: 1000px; /* 限制内容最大宽度 */
}

.course-type-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 25px 15px;
  border-radius: 12px;
  border: 1px solid #e5e7eb;
  cursor: pointer;
  transition: all 0.3s ease;
  text-align: center;
  min-height: 160px;
  justify-content: center;
  background-color: #fff;
}

.course-type-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 10px 20px rgba(0, 132, 255, 0.15);
  border-color: #0084ff;
  background-color: rgba(0, 132, 255, 0.03);
}

.course-icon {
  font-size: 32px;
  margin-bottom: 15px;
  color: #0084ff;
  transition: transform 0.3s ease;
}

.course-type-card:hover .course-icon {
  transform: scale(1.1);
}

.course-name {
  font-size: 17px;
  font-weight: 500;
  color: #333;
}

/* 小屏幕适配 */
@media screen and (max-width: 576px) {
  .course-type-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
  }

  .course-type-card {
    padding: 20px 10px;
    min-height: 140px;
  }

  .course-icon {
    font-size: 28px;
  }
}
</style>
